<template>
  <!-- 接受中标 -->
  <el-dialog
    v-model="props.visible"
    width="800px"
    :show-close="false"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <template #header="{ close, titleId, titleClass }">
      <div class="my-header">
        <h4
          :id="titleId"
          :class="titleClass"
        >
          {{ t('userCenter.t3') }}
        </h4>
        <img
          src="@/assets/img/icon_guanbi.png"
          @click="close"
          class="close"
        />
      </div>
    </template>

    <div>{{ t('userCenter.text1') }}</div>
    <div
      v-for="item in confirmQuotaBoList"
      :key="item.id"
      class="mt-1"
    >
      <!-- {{ getDictLabel('win_bid_condition', item.acceptCondition) }},  -->
      {{ item.acceptConditionDescription }}
    </div>

    <template #footer>
      <div class="dialog-footer flexcc">
        <el-button
          color="#252628"
          plain
          @click="cancel"
        >
          {{ t('cancelText') }}
        </el-button>
        <el-button
          type="primary"
          color="#252628"
          @click="confirm"
        >
          {{ t('confirmText') }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { onBeforeMount, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { acceptConditionListApi } from '@/service/common.js'
import { acceptanceQuotationApi as dockOrderAcceptanceQuotationApi } from '@/service/dockOrder'
import { acceptanceQuotationApi as procurementAcceptanceQuotationApi } from '@/service/procurement'
import { acceptanceQuotationApi as externalAssistanceAcceptanceQuotationApi } from '@/service/externalAssistance'

import useDict from '@/hooks/useDict'
const { dictData, getDictData, getDictLabel } = useDict()

const { t, locale } = useI18n()

onBeforeMount(() => {
  init()
})

const props = defineProps({
  visible: {
    type: Boolean,
    default: false
  },
  // 报价单id
  quotationId: {
    type: [String, Number],
    required: true
  },
  // 1 2 3
  type: {
    type: [String, Number],
    default: 1
  }
})

const emit = defineEmits(['close', 'getList'])

const handleClose = () => {
  emit('close')
}

// 取消
const cancel = () => {
  handleClose()
}

// 确定
const confirm = () => {
  const obj = {
    1: dockOrderAcceptanceQuotationApi,
    2: procurementAcceptanceQuotationApi,
    3: externalAssistanceAcceptanceQuotationApi
  }

  obj[props.type]({
    quotationId: props.quotationId
  }).then(({ msg }) => {
    ElMessage.success(msg)
    handleClose()
    emit('getList')
  })
}

// 回显中标条件
const confirmQuotaBoList = ref([])
const getConditions = () => {
  const obj = {
    1: 'shcw_quotation_dock_order',
    2: 'shcw_quotation_procure_order',
    3: 'shcw_quotation_assist_order'
  }

  acceptConditionListApi({
    objId: props.quotationId,
    objTable: obj[props.type]
  }).then(({ data }) => {
    confirmQuotaBoList.value = data
  })
}

const init = async () => {
  await getDictData('win_bid_condition')
  getConditions()
}
</script>

<style scoped lang="scss"></style>
